{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Flask App\n",
    "From the another notebook (such as `run_flask.ipynb`), you can run the flask app in a cell and test it from here using python http or `curl` statements.\n",
    "\n",
    "```python\n",
    "# run_flask.ipynb\n",
    "!FLASK_APP=wsgi.py flask run\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"status\": \"ok\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "!curl http://localhost:5000/status"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"prediction\": \"No Sepsis\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "!curl -X POST -H \"Content-Type: application/json\" --data '{\"HR\": 103, \"O2Sat\": 90, \"Temp\": null, \"SBP\": null, \"MAP\": null, \"DBP\": null, \"Resp\": 30, \"EtCO2\": null, \"BaseExcess\": 21, \"HCO3\": 45, \"FiO2\": null, \"pH\": 7.37, \"PaCO2\": 90, \"SaO2\": 91, \"AST\": 16, \"BUN\": 14, \"Alkalinephos\": 98, \"Calcium\": 9.3, \"Chloride\": 85, \"Creatinine\": 0.7, \"Glucose\": 193, \"Lactate\": null, \"Magnesium\": 2, \"Phosphate\": 3.3, \"Potassium\": 3.8, \"Bilirubin_total\": 0.3, \"Hct\": 37.2, \"Hgb\": 12.5, \"PTT\": null, \"WBC\": 5.7, \"Fibrinogen\": null, \"Platelets\": 317}' http://127.0.0.1:5000/predictions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'prediction': 'No Sepsis'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "data = {\"HR\":103,\"O2Sat\":90,\"Temp\": None,\"SBP\": None,\"MAP\": None,\"DBP\": None,\"Resp\":30,\"EtCO2\": None,\"BaseExcess\":21,\"HCO3\":45,\"FiO2\": None,\"pH\":7.37,\"PaCO2\":90,\"SaO2\":91,  \"AST\":16, \"BUN\":14, \"Alkalinephos\":98, \"Calcium\":9.3, \"Chloride\":85, \"Creatinine\":0.7, \"Glucose\":193,  \"Lactate\": None,  \"Magnesium\":2,  \"Phosphate\":3.3,\"Potassium\":3.8,\"Bilirubin_total\":0.3,\"Hct\":37.2,\"Hgb\":12.5,\"PTT\": None,\"WBC\":5.7, \"Fibrinogen\": None,\"Platelets\":317}\n",
    "response = requests.post('http://127.0.0.1:5000/predictions', data=json.dumps(data))\n",
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "collapsed_sections": [],
   "name": "Object detection",
   "private_outputs": true,
   "provenance": [],
   "toc_visible": true
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
